package chpt11;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class QuantifierTest {
	public static void main(String[] args) {
		String greedy_regex = "\\d+\\d";
		String reluctant_regex = "\\d+?\\d";
		String possessive_regex = "\\d++\\d";
		String str = "123 456";
		Pattern p1 = Pattern.compile(greedy_regex);
		Matcher m1 = p1.matcher(str);
		System.out.println("贪婪型量词匹配结果：");
		while(m1.find()) {
			System.out.println(m1.group());			
		}
		
		Pattern p2 = Pattern.compile(reluctant_regex);
		Matcher m2 = p2.matcher(str);
		System.out.println("勉强型量词匹配结果：");
		while(m2.find()) {
			System.out.println(m2.group());			
		}
		
		Pattern p3 = Pattern.compile(possessive_regex);
		Matcher m3 = p3.matcher(str);
		System.out.println("占有型量词匹配结果：");
		while(m3.find()) {
			System.out.println(m3.group());			
		}
	}
}
